package com.example.k8s.hello.bean.sys.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.example.k8s.hello.bean.sys.constant.SysConstant;
import com.example.k8s.hello.common.utils.CopyUtils;
import com.example.k8s.hello.common.bean.LoginUser;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 系统用户
 *
 * @author Mark sunlightcs@gmail.com
 */
@Data
@Accessors(chain = true)
@TableName("sys_user")
@Schema(description = "系统用户")
public class SysUserEntity implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@TableId
	@Schema(description = "用户ID")
	private Long userId;

	@Schema(description = "学号")
	private String username;

	@Schema(description = "姓名")
	private String nickname;

	@Schema(description = "密码")
	private String password;

	@Schema(description = "邮箱")
	private String email;

	@Schema(description = "手机号")
	private String mobile;

	@Schema(description = "状态  0：禁用   1：正常")
	private Integer status;

	@Schema(description = "角色ID列表")
	@TableField(exist=false)
	private List<Long> roleIdList;

	@Schema(description = "创建者ID")
	@TableField(fill = FieldFill.INSERT)
	private Long createUserId;

	@Schema(description = "创建时间")
	@TableField(fill = FieldFill.INSERT)
//	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;

	public LoginUser buildLoginUser() {
		LoginUser loginUser = CopyUtils.copy(this, LoginUser.class);
		loginUser.setIfAdmin(Objects.equals(userId.intValue(), SysConstant.SUPER_ADMIN));

		return loginUser;
	}
}
